package com.elinkway.infinitemovies.async;

import android.content.Context;

import com.elinkway.infinitemovies.bean.PlaySrcList;
import com.elinkway.infinitemovies.bean.VideoDataBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.VideoListParser;
import com.lvideo.http.bean.LVideoDataHull;

public class RequestEpisodesTask extends MoviesHttpAsyncTask<VideoDataBean> {


	public RequestEpisodesTask(Context context) {
		super(context);
	}

	public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getAid() {
        return aid;
    }

    public void setAid(String aid) {
        this.aid = aid;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    private String site ="";
	private String aid  ="";
	private VideoDataBean video;
	private RequestResultListener<VideoDataBean> mListener;
	private int pageIndex = 1;
	private int pageSize = 1;
	
	public RequestEpisodesTask(Context context, String site, String aid) {
		super(context);
		this.aid=aid;
		this.site=site;
	}

	@Override
	public LVideoDataHull<VideoDataBean> doInBackground() {
		PlaySrcList siteList = video.getSrcList();
		String site = video.getSubsrc();
		// 设置播放源播放地址，剧集信息等
		if (null != siteList && null != siteList.getPlaySrcList() && !siteList.getPlaySrcList().isEmpty()){
			site = siteList.getPlaySrcList().get(0).getSite();
		}

		return MoviesHttpApi.requestVideoList(new VideoListParser(site,video,pageIndex), site,aid,pageIndex,pageSize);
	}

	@Override
	public void onPostExecute(int updateId, VideoDataBean result) {
		if(null != mListener){
			mListener.onRequestSuccess(updateId, result);
		}
	}

	@Override
	public boolean onPreExecute() {
		if(null != mListener){
			mListener.onPreRequest();
		}
		return super.onPreExecute();
	}
	
	@Override
	public void netNull() {
		if(null != mListener){
			mListener.onRequestFailed();
		}
		super.netNull();
	}
	
	@Override
	public void netErr(int updateId, String errMsg) {
		if(null != mListener){
			mListener.onRequestFailed();
		}
		super.netErr(updateId, errMsg);
	}
	
	@Override
	public void dataNull(int updateId, String errMsg) {
		if(null != mListener){
			mListener.onRequestFailed();
		}
		super.dataNull(updateId, errMsg);
	}

	public RequestResultListener<VideoDataBean> getmListener() {
		return mListener;
	}

	public void setmListener(RequestResultListener<VideoDataBean> mListener) {
		this.mListener = mListener;
	}
	
	public void setParams(String site, String aid,VideoDataBean video){
		this.site=site;
		this.aid=aid;
		this.video=video;
	}
}
